home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / UUPC3 / (UUPC__) / UUHOST.C < prev   
Text File  |  1992-02-10  |  21KB  |  881 lines

  1. /*        uuhost.c
  2.  
  3. */
  4. #define    MAIN    dcpmain
  5. #define CWDSPOOL
  6.  
  7. /*** #include    "host.c" ***/
  8. /*** host.c file included below:: ***/
  9. /*        mac.c
  10.  
  11.         macintosh host 
  12.  
  13.             Portions Copyright ⌐ Gary Morris, 1991.  All Rights Reserved Worldwide.
  14.  
  15.             Portions Copyright ⌐ David Platt, 1992, 1991.  All Rights Reserved
  16.             Worldwide.
  17.  
  18. */
  19.  
  20. #include <stdio.h>
  21. /* #include "host.h" */
  22. #include "dcp.h"
  23. #include <string.h>
  24. #include <ctype.h>
  25. #include <setjmp.h>
  26. #include <errno.h>
  27.  
  28. # ifdef THINK_C
  29. # include <console.h>
  30. # include <pascal.h>
  31. #endif THINK_C
  32.  
  33. /* about dialog id */
  34. #define Debug_Level_Id  (1011)
  35. #define About_Dlog_Id    (1010)
  36. #define Cmd_Dlog_Id        (1000)
  37.  
  38. typedef enum {
  39.     OK_Button=1, Cancel_Button,
  40.     Slave_RButton, Master_RButton,
  41.     Call_Any_RButton, Call_All_RButton, Call_One_RButton, Call_Schedule,
  42.     Call_Need, Call_Autopilot,
  43. #ifdef DEF_FRAME
  44.     Site_Name_Text, Debug_Level_Text, Debug_Level_Title, D_Default
  45. #else DEF_FRAME
  46.     Site_Name_Text, Debug_Level_Text
  47. #endif DEF_FRAME
  48. } Cmd_Dlog_Items;
  49.  
  50. typedef enum {
  51.     OK_Button2=1, Cancel_Button2,
  52.     Debug_Level_Item, Button0, Button1, Button5, Debug_Default_Item } Debug_Level_Items;
  53.  
  54. /* menu id numbers */
  55. #define N_Menus 4
  56. enum Menu_Ids {Apple_Menu_Id=1, File_Menu_Id=1000, Edit_Menu_Id, Call_Menu_Id};
  57.                 
  58. /* menu item list numbers */         
  59. enum Menu_Indexes {Apple_Menu_Index, File_Menu_Index, Edit_Menu_Index, Call_Menu_Index};
  60. enum File_Menu_Items {Open_And_Call_Item=1, Call_System_Item, Cancel_Call_Item, Separator1, 
  61.                       Debug_Item, Separator2, Abort_Program_Item,
  62.                       Separator3, Quit_Item};
  63. enum Edit_Menu_Items {Undo_Item=1, Cut_Item=3, Copy_Item, Paste_Item, Clear_Item};
  64. enum Call_Menu_Items {All_Sites=1, Any_Site=2, Per_Schedule=3, Need=4, Slave_Mode=6, Autopilot=7, 
  65.                       Specific_Site=9};
  66.  
  67. static MenuHandle My_Menus[N_Menus];                /* indexed by Menu_Indexes */
  68.  
  69. #define N_Specific_Sites 256
  70.  
  71. static char **Sitenames[N_Specific_Sites];
  72. static int siteCount = 0;
  73.  
  74.  
  75.  
  76. char *curdir;
  77. char * getcwd();
  78. FILE * FOPEN();
  79.  
  80. int CHDIR();
  81. int    debuglevel;        /* debugging level */
  82.  
  83. int Main_State = Idle_System;
  84. int Background = FALSE;
  85.  
  86. #ifdef Upgrade
  87. long int systimeout = 0;
  88. #endif Upgrade
  89.  
  90. char *n_argv[10];
  91. char line[128];
  92.  
  93. #ifdef STANDALONE
  94. # define DMAILBOX    "mailbox"
  95. # define    DNAME        ""
  96. # define DHOME        "/usr/home/guest"
  97. # define    DDOMAIN        "mac.uucp"
  98. # define    DMAILDIR    "/usr/spool/mail"
  99. # define    DCONFDIR    "/usr/lib/uucp"
  100. # define    DSPOOLDIR    "/usr/spool/uucp"
  101. # define DPUBDIR        "/usr/spool/uucppublic"
  102. # define    DMAILSERVICE    "crash"
  103. # define    DNODENAME    "shappy"
  104. # define    DDEVICE        "modem"
  105. # define    DSPEED        "2400"
  106. # define    DTEMPDIR    "/usr/tmp"
  107.  
  108. FILE *fe;
  109.  
  110. void
  111. sgenv(thename, envname, dflt)
  112.     char **thename;
  113.     char *envname;
  114.     char *dflt; {
  115.     char line[BUFSIZ];
  116.  
  117.     fprintf( stderr, "genv: %s %s\n", envname, dflt ); /**/
  118.     
  119.     if (fgets( line, BUFSIZ, fe ) == NULL) {
  120.         fprintf( stderr, "genv: %s not found, using %s\n", envname, dflt ); /* */
  121.         strcpy( *thename, dflt);
  122.     }
  123.     else {
  124.         strcpy( *thename, line);
  125.         fprintf( stderr, "genv: %s %s\n", envname, *thename ); /**/
  126.     }
  127. }
  128.  
  129. void sloadenv()
  130. {
  131.     fprintf( stderr, "sloadenv\n" );
  132.     if ( (fe = FOPEN( "/usr/lib/uucp/defaults", "r" )) == (FILE *) NULL ) {
  133.         fprintf( stderr, "can't open /usr/lib/uucp/defaults  %d\n", errno );
  134.         exit( -1 );
  135.     }
  136.     fprintf( stderr, "sloadenv - fopened\n" );
  137.     /* get environment var's */
  138.     sgenv( &name, NAME, DNAME );
  139.     sgenv( &mailbox, MAILBOX, DMAILBOX );
  140.     sgenv( &nodename, NODENAME, DNODENAME );
  141.     sgenv( &home, HOME, DHOME );
  142.     sgenv( &domain, DOMAIN, DDOMAIN );
  143.     sgenv( &maildir, MAILDIR, DMAILDIR );
  144.     sgenv( &confdir, CONFDIR, DCONFDIR );
  145.     sgenv( &spooldir, SPOOLDIR, DSPOOLDIR );
  146.     sgenv( &pubdir, PUBDIR, DPUBDIR );
  147.     sgenv( &mailserv, MAILSERVICE, DMAILSERVICE );
  148.     sgenv( &device, DEVICE, DDEVICE );
  149.     sgenv( &speed, SPEED, DSPEED );
  150.     sgenv( &tempdir, TEMPDIR, DTEMPDIR );
  151.     
  152.     fclose(fe);
  153. }
  154. #endif
  155.  
  156. #ifdef DEF_FRAME
  157. pascal void Draw_Ring(WindowPtr W, int Item);
  158.  
  159. pascal void Draw_Ring(W, Item)
  160. WindowPtr W; 
  161. int Item;
  162. {
  163.     int Item_Type;
  164.     Handle H;
  165.     Rect R;
  166.     
  167.     /* set the graphport */
  168.     SetPort((GrafPtr)W);
  169.  
  170.     GetDItem(W, Item, &Item_Type, &H, &R);
  171.  
  172.     PenNormal();
  173.     PenSize(3, 3);
  174.     FrameRoundRect(&R, 16, 16);
  175.     PenNormal();
  176. }
  177. #endif DEF_FRAME
  178.  
  179. char *gets();
  180.  
  181. void Set_Main_State(int New_State);
  182.  
  183. void Set_Main_State(New_State)
  184. int New_State;
  185. {
  186.     switch (Main_State) {
  187.       case Cancel_Call:
  188.           if (New_State == Call_Systems) return;
  189.           break;
  190.       case Quit_Program:
  191.           /* once in this state, don't change, wait for the program to end */
  192.           if (New_State != Idle_System && New_State != Abort_Program) 
  193.               return;
  194.           break;
  195.       case Abort_Program:
  196.           /* once in this state, don't change, wait for the program to end */
  197.           break;
  198.     }
  199.     
  200.     switch (New_State) {
  201.         case Idle_System:
  202.             EnableItem(My_Menus[File_Menu_Index], Open_And_Call_Item);
  203.             EnableItem(My_Menus[File_Menu_Index], Call_System_Item);
  204.             DisableItem(My_Menus[File_Menu_Index], Cancel_Call_Item);
  205.             DisableItem(My_Menus[File_Menu_Index], Abort_Program_Item);
  206.             EnableItem(My_Menus[Call_Menu_Index], 0);
  207.             HiliteMenu(0);
  208.                DrawMenuBar();
  209.             printmsg(0, "Idle");
  210.             break;
  211.         
  212.         case Call_Systems:
  213.             DisableItem(My_Menus[File_Menu_Index], Open_And_Call_Item);
  214.             DisableItem(My_Menus[File_Menu_Index], Call_System_Item);
  215.             EnableItem(My_Menus[File_Menu_Index], Cancel_Call_Item);
  216.             EnableItem(My_Menus[File_Menu_Index], Abort_Program_Item);
  217.             DisableItem(My_Menus[Call_Menu_Index], 0);
  218.             HiliteMenu(0);
  219.                DrawMenuBar();
  220.             break;
  221.         
  222.         case Cancel_Call:
  223.             DisableItem(My_Menus[File_Menu_Index], Cancel_Call_Item);
  224.             SIOInterrupt();
  225.             printmsg(0, "Cancellation requested");
  226.             PlayNamed("\pCancel");
  227.             break;
  228.         
  229.         case Abort_Program:
  230.             PlayNamed("\pAbort");
  231.             break;
  232.  
  233.         case Quit_Program:
  234.             SIOInterrupt();
  235.             break;
  236.     }
  237.     
  238.     Main_State = New_State;
  239. }
  240.  
  241. #ifdef MULTIFINDER
  242. void Do_Command(long Menu_Command);
  243. void Do_Mouse_Action(EventRecord *Cur_Event);
  244.  
  245.  
  246. void Set_RButton(DialogPtr Dlog,int Item,int Min,int Max);
  247. void Hilite_Buttons(DialogPtr Dlog,int Min,int Max, int Value);
  248. int Get_Command_Options(void);
  249.  
  250. void Hilite_Buttons(Dlog, Min, Max, Value)
  251. DialogPtr Dlog;
  252. int Min, Max;
  253. int Value;
  254. {
  255.     int i;
  256.     int Item_Type;
  257.     Handle H;
  258.     Rect R;
  259.     
  260.     for (i=Min; i<=Max; i++) {
  261.         GetDItem(Dlog, i, &Item_Type, &H, &R);
  262.         HiliteControl(H, (Value==1) ? 0 : 255);
  263.     }
  264. }
  265.  
  266. void Set_RButton(Dlog,Item,Min,Max)
  267. DialogPtr Dlog;
  268. int Item;
  269. int Min,Max;
  270. {
  271.     int i;
  272.     int Item_Type;
  273.     Handle H;
  274.     Rect R;
  275.     
  276.     for (i=Min; i<=Max; i++) {
  277.         GetDItem(Dlog, i, &Item_Type, &H, &R);
  278.         SetCtlValue(H, (i==Item ? 1 : 0));
  279.     }
  280. }
  281.  
  282. int Get_Debug_Level(void);
  283.  
  284. int Get_Debug_Level()
  285. {
  286.     int Item_Hit = 0;
  287.     DialogPtr DL_Dlog;
  288.     int Debug_Level = debuglevel;
  289.     int Item_Type;
  290.     Handle H;
  291.     Rect R;
  292.     
  293.     /* open debug level dialog */
  294.     DL_Dlog = GetNewDialog(Debug_Level_Id, (Ptr) 0, -1);
  295.  
  296. #ifdef DEF_FRAME
  297.     /* hilite the default (D_Default) placeholder */
  298.     GetDItem(DL_Dlog, Debug_Default_Item,  &Item_Type, &H, &R);
  299.     InsetRect(&R, -4, -4);
  300.     SetDItem(DL_Dlog, Debug_Default_Item, userItem, Draw_Ring, &R);
  301. #endif DEF_FRAME
  302.     
  303.     GetDItem(DL_Dlog, Debug_Level_Item, &Item_Type, &H, &R);
  304.     sprintf(line, "%d", Debug_Level);
  305.     CtoPstr(line);
  306.     SetIText(H, line);
  307.     SelIText(DL_Dlog, Debug_Level_Item, 0, 32767);
  308.     
  309.     Item_Hit = 0;
  310.     while (Item_Hit != OK_Button && Item_Hit != Cancel_Button) {
  311.         ModalDialog((ProcPtr) 0, &Item_Hit);
  312.     
  313.         switch (Item_Hit) {
  314.             case Button0:
  315.                 Debug_Level = 0;
  316.                 break;
  317.             
  318.             case Button1:
  319.                 Debug_Level = 1;
  320.                 break;
  321.             
  322.             case Button5:
  323.                 Debug_Level = 5;
  324.                 break;
  325.             
  326.             case OK_Button:
  327.                 GetIText(H, line);
  328.                 PtoCstr(line);
  329.                 sscanf(line, "%d", &Debug_Level);
  330.                 debuglevel = Debug_Level;
  331.                 if (debuglevel < 0) debuglevel = 0;
  332.                 if (debuglevel >10) debuglevel = 10;
  333.                 break;
  334.         }
  335.         
  336.         if (Item_Hit >= Button0 && Item_Hit <= Button5) {
  337.             sprintf(line, "%d", Debug_Level);
  338.             CtoPstr(line);
  339.             SetIText(H, line);
  340.         }
  341.     }
  342.         
  343.     DisposDialog(DL_Dlog);
  344. }
  345.     
  346. int Get_Command_Options()
  347. {
  348.     int Item_Hit = 0;
  349.     DialogPtr Cmd_Dlog;
  350.     int Master = 1;
  351.     int Callee = Call_Schedule;
  352.     char Callee_Str[16];
  353.     int Debug_Level = debuglevel;
  354.     int Item_Type;
  355.     Handle H;
  356.     Rect R;
  357.     
  358.     /* open simulation dialog */
  359.     Cmd_Dlog = GetNewDialog(Cmd_Dlog_Id, (Ptr) 0, -1);
  360.     
  361.     Set_RButton(Cmd_Dlog, Master_RButton, Slave_RButton, Master_RButton);
  362.     Set_RButton(Cmd_Dlog, Call_Schedule,  Call_Any_RButton, Call_Autopilot);
  363.     
  364.     GetDItem(Cmd_Dlog, Debug_Level_Text, &Item_Type, &H, &R);
  365.     sprintf(line, "%d", Debug_Level);
  366.     CtoPstr(line);
  367.     SetIText(H, line);
  368.     
  369.     GetDItem(Cmd_Dlog, Site_Name_Text, &Item_Type, &H, &R);
  370.     strcpy(Callee_Str, mailserv);
  371.     CtoPstr(Callee_Str);
  372.     SetIText(H, Callee_Str);
  373.     SelIText(Cmd_Dlog, Site_Name_Text, 0, 32767);
  374.  
  375. #ifdef DEF_FRAME
  376.     /* hilite the default (D_Default) placeholder */
  377.     GetDItem(Cmd_Dlog, D_Default,  &Item_Type, &H, &R);
  378.     InsetRect(&R, -4, -4);
  379.     SetDItem(Cmd_Dlog, D_Default, userItem, Draw_Ring, &R);
  380. #endif DEF_FRAME
  381.     
  382.     Item_Hit = 0;
  383.     while (Item_Hit != OK_Button && Item_Hit != Cancel_Button) {
  384.         ModalDialog((ProcPtr) 0, &Item_Hit);
  385.     
  386.         switch (Item_Hit) {
  387.             case Master_RButton:
  388.             case Slave_RButton:
  389.                 Set_RButton(Cmd_Dlog, Item_Hit, Slave_RButton, Master_RButton);
  390.                 Master = (Item_Hit == Master_RButton) ? 1 : 0;
  391.                 Hilite_Buttons(Cmd_Dlog, Call_Any_RButton, Call_Autopilot, Master);
  392.                 break;
  393.                 
  394.             case Call_Any_RButton:
  395.             case Call_All_RButton:
  396.             case Call_One_RButton:
  397.             case Call_Schedule:
  398.             case Call_Need:
  399.             case Call_Autopilot:
  400.                 Callee = Item_Hit;
  401.                 Set_RButton(Cmd_Dlog, Callee, Call_Any_RButton, Call_Autopilot);
  402.                 break;
  403.             case OK_Button:
  404.                 Set_Main_State(Call_Systems);
  405.                 break;
  406.             case Cancel_Button:
  407.                 Set_Main_State(Idle_System);
  408.                 break;
  409.             case Site_Name_Text:
  410.                 Callee = Call_One_RButton;
  411.                 Set_RButton(Cmd_Dlog, Callee, Call_Any_RButton, Call_Autopilot);
  412.                 break;
  413.         }
  414.     }
  415.  
  416.     if (Main_State == Call_Systems) {
  417.         /* extract debug level from dialog box */
  418.         GetDItem(Cmd_Dlog, Debug_Level_Text, &Item_Type, &H, &R);
  419.         GetIText(H, line);
  420.         PtoCstr(line);
  421.         sscanf(line,"%d",&Debug_Level);
  422.         
  423.         switch (Callee) {
  424.             case Call_Any_RButton:
  425.                 strcpy(Callee_Str, "any");
  426.                 break;
  427.             case Call_All_RButton:
  428.                 strcpy(Callee_Str, "all");
  429.                 break;
  430.             case Call_One_RButton:
  431.                 GetDItem(Cmd_Dlog, Site_Name_Text, &Item_Type, &H, &R);
  432.                 GetIText(H, Callee_Str);
  433.                 PtoCstr(Callee_Str);
  434.                 break;
  435.             case Call_Schedule:
  436.                 strcpy(Callee_Str, "cron");
  437.                 break;
  438.             case Call_Need:
  439.                 strcpy(Callee_Str, "need");
  440.                 break;
  441.             case Call_Autopilot:
  442.                 strcpy(Callee_Str, "auto");
  443.                 break;
  444.         }
  445.         sprintf(line, "-r%d -x%d -s%s", Master, Debug_Level, Callee_Str); 
  446.     }
  447.         
  448.     DisposDialog(Cmd_Dlog);
  449.         
  450. }
  451.  
  452. void Do_Command(Menu_Command)
  453. long Menu_Command;
  454. {
  455.     int The_Menu;    /* the menu selected */
  456.     int The_Item;    /* the item in the menu */
  457.     Str255 Name;    /* name of DA selected */
  458.     int Ref_Num;    /* reference number of the DA */
  459.     int siteIndex;    /* index number of site to call */
  460.     long dticks;
  461.     Point sfBox;
  462.     SFReply sfReply;
  463.     SFTypeList myType;
  464.         
  465.     The_Menu = HiWord(Menu_Command);
  466.     The_Item = LoWord(Menu_Command);
  467.     
  468.     switch (The_Menu) {
  469.         case Apple_Menu_Id:
  470.             /* open DA with item's name */
  471.             if (The_Item == 1) {
  472.                 /* show about box */
  473.                 int Item_Hit;
  474.                 DialogPtr About_Dlog;
  475.                 
  476.                 /* open about dialog */
  477.                 About_Dlog = GetNewDialog(About_Dlog_Id, (Ptr) 0, -1);
  478.                 ModalDialog((ProcPtr) 0, &Item_Hit);
  479.                 DisposDialog(About_Dlog);
  480.             } else {
  481.                 GetItem(My_Menus[Apple_Menu_Index],The_Item,Name);
  482.                 Ref_Num = OpenDeskAcc(Name);
  483.             }
  484.             break;
  485.             
  486.         case File_Menu_Id:
  487.             switch (The_Item) {
  488.                 case Open_And_Call_Item:
  489.                     sfBox.h = 100;
  490.                     sfBox.v = 50;
  491.                     myType[0] = (OSType) 'CALL';
  492.                     SFGetFile(sfBox, (unsigned char *) "\p", (ProcPtr) NULL, -1, &myType, (ProcPtr) NULL, &sfReply);
  493.                     if (sfReply.good) {
  494.                         PtoCstr((char *) sfReply.fName);
  495.                         sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, sfReply.fName);
  496.                         Set_Main_State(Call_Systems);
  497.                     }
  498.                     break;
  499.                    case Call_System_Item:
  500.                     /* call which system?  put up dialog */
  501.                     Set_Main_State(Call_Systems);
  502.                     Get_Command_Options();
  503.                     break;
  504.                 
  505.                 case Cancel_Call_Item:
  506.                     Set_Main_State(Cancel_Call);
  507.                     Delay(15, &dticks);
  508.                     break;
  509.                     
  510.                 case Debug_Item:
  511.                     Get_Debug_Level();
  512.                     break;
  513.                     
  514.                 case Abort_Program_Item:
  515.                     Set_Main_State(Abort_Program);
  516.                     Delay(15, &dticks);
  517.                     break;
  518.                     
  519.                 case Quit_Item:
  520.                     Set_Main_State(Quit_Program);    /* exit at next opportunity */
  521.                     Delay(15, &dticks);
  522.                     break;
  523.             }
  524.             HiliteMenu(0);        /* unhilite menu bar */
  525.             break;
  526.             
  527.         case Edit_Menu_Id:
  528.             /* process edit command if not System's */
  529.             if (!SystemEdit(The_Item-1)) {
  530.                 Delay(15, &dticks);
  531.                 switch (The_Item) {
  532.                     case Undo_Item:
  533.                         /* UNDO */
  534.                         break;
  535.                     case Cut_Item: 
  536.                         /* CUT */
  537.                         break;
  538.                     case Copy_Item:
  539.                         /* COPY */
  540.                         break;
  541.                        case Paste_Item:
  542.                         /* PASTE */
  543.                         break;
  544.                     case Clear_Item:
  545.                         /* CLEAR */
  546.                         break;
  547.                 }
  548.             }
  549.             break;
  550.             
  551.         case Call_Menu_Id:
  552.             Set_Main_State(Call_Systems);
  553.             switch(The_Item) {
  554.                 case All_Sites:
  555.                     sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, "all");
  556.                     break;
  557.                 case Any_Site:
  558.                     sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, "any");
  559.                     break;
  560.                 case Per_Schedule:
  561.                     sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, "cron");
  562.                     break;
  563.                 case Slave_Mode:
  564.                     sprintf(line, "-r%d -x%d -s%s", 0, debuglevel, "any");
  565.                     break;
  566.                 case Need:
  567.                     sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, "need");
  568.                     break;
  569.                 case Autopilot:
  570.                     sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, "auto");
  571.                     break;
  572.                 default:
  573.                     siteIndex = The_Item - (int) Specific_Site;
  574.                     if (siteIndex >= 0 && siteIndex < siteCount) {
  575.                         HLock(Sitenames[siteIndex]);
  576.                         sprintf(line, "-r%d -x%d -s%s", 1, debuglevel, *Sitenames[siteIndex]);
  577.                         HUnlock(Sitenames[siteIndex]);
  578.                     } else {
  579.                         Set_Main_State(Idle_System);
  580.                         SysBeep(10);
  581.                     }
  582.                     break;
  583.             }
  584.         break;
  585.                 
  586.     }
  587. }
  588.  
  589.  
  590. void Do_Mouse_Action(Cur_Event)
  591. EventRecord *Cur_Event;
  592. {
  593.     WindowPeek Which_Window;
  594.     int code = FindWindow(Cur_Event->where,&Which_Window);
  595.  
  596.     switch (code) {
  597.         case inDesk:
  598.             SysBeep(10);
  599.             break;
  600.         case inMenuBar:
  601.             Do_Command(MenuSelect(Cur_Event->where));
  602.             HiliteMenu(0);
  603.             break;
  604.         case inSysWindow:
  605.             SystemClick(Cur_Event,Which_Window);
  606.             break;
  607.         case inContent:
  608.             /* should already be handled by DialogSelect */
  609.             break;
  610.         case inDrag:
  611.             /* we don't have any windows to drag */
  612.             break;
  613.         case inGrow:
  614.             /* no action, main window has no grow box */
  615.             break;
  616.         case inGoAway:
  617.             /* we don't have any window to make go away */
  618.             break;
  619.         }
  620. }
  621.  
  622. long Last_Check_Event = 0;
  623.  
  624. int Check_Events(Sleep_Time)
  625. long Sleep_Time;
  626. {
  627. /* #define osEvt app4Evt */
  628. #define suspend 1
  629. #define mouseMoved 0xFA
  630. #define resumeMask 1
  631.  
  632.     EventRecord Cur_Event;
  633.     long dticks;
  634.     int Event_Mask = keyDownMask | mDownMask | mUpMask | keyUpMask | autoKeyMask |
  635.                      updateMask | activMask | diskEvt;
  636.     
  637.     static int inited = 0;
  638.     static RgnHandle Mouse_Rgn;
  639.     static Point badMountPoint = {100, 100};
  640.  
  641.     
  642.     if (inited == 0) {
  643.         Mouse_Rgn = NewRgn();
  644.         SetRectRgn(Mouse_Rgn,
  645.                    screenBits.bounds.left,
  646.                    screenBits.bounds.top,
  647.                    screenBits.bounds.right,
  648.                    screenBits.bounds.bottom);
  649.         inited = 1;
  650.     }
  651.     
  652.     (void) WaitNextEvent(Event_Mask, &Cur_Event, Sleep_Time, (Handle) NULL);    
  653.  
  654.     /* any events for us? */
  655.     switch (Cur_Event.what) {
  656.         case keyDown:
  657.             if (Cur_Event.modifiers & cmdKey) {
  658.                 SetCursor(&arrow);
  659.                 Do_Command(MenuKey((char) Cur_Event.message & 0xFF));
  660.                 Delay(15,&dticks);
  661.                 HiliteMenu(0);   /* unhilite after it's seen */
  662.             } 
  663.             break;        
  664.                     
  665.         case mouseDown:
  666.             SetCursor(&arrow);
  667.             Do_Mouse_Action(&Cur_Event);
  668.             break;
  669.         
  670.         case diskEvt:
  671.             if ((Cur_Event.message >> 16) != noErr) {
  672.                 (void) DIBadMount(badMountPoint, Cur_Event.message);
  673.             }
  674.             break;
  675.             
  676.         case activateEvt:
  677.             if (Cur_Event.modifiers & activeFlag) {
  678.                 /* set port to the window becoming activated */
  679.                 SetPort((WindowPtr) Cur_Event.message);
  680.             }
  681.             break;
  682.                     
  683.         case updateEvt:
  684.             break;
  685.                     
  686.         case osEvt:
  687.             if (((Cur_Event.message >> 24) & 0xFF) == suspend) {
  688.                 Background = (Cur_Event.message & resumeMask) ? FALSE : TRUE;
  689.                 /* switch to background or foreground */
  690.             }
  691.             break;
  692.     }
  693.     
  694.     Last_Check_Event = Ticks;
  695.     
  696.     return (Main_State == Cancel_Call) || (Main_State == Quit_Program) || 
  697.            (Main_State == Abort_Program) || (Main_State == Shutdown_Program);
  698. }
  699. #endif
  700.  
  701. int Count_Appl_Files(void);
  702. int Count_Appl_Files()
  703. {
  704.     int message, count;
  705.     
  706.     CountAppFiles(&message, &count);
  707.     
  708.     return count;
  709. }
  710.  
  711. void AppendToCallMenu(void);
  712.  
  713. void AppendToCallMenu()
  714. {
  715.     char state;
  716.     int i, j;
  717.     char **t;
  718.     mkfilename( line, confdir,  SYSTEMS );
  719.     if (strchr(confdir, SEPCHAR) == NULL && strchr(confdir, DIRCHAR) == NULL)
  720.         /* make it an absolute pathname */
  721.         mkfilename(s_systems, curdir, line);
  722.     else
  723.         strcpy(s_systems, line);
  724.     if (( fsys = FOPEN( s_systems, "r", 't' )) == (FILE *)NULL ) {
  725.         return;
  726.     }
  727.     while (TRUE) {
  728.         if (siteCount >= N_Specific_Sites) break;
  729.         state = getsystem("list");
  730.         if (state == 'A') break;
  731.         if (strcmp(rmtname, "INCOMING") == SAME || strcmp(rmtname, "ANONYMOUS") == SAME) {
  732.             goto scanNext;
  733.         }
  734.         for (i = 0; i < siteCount; i++) {
  735.             if (strcmp(rmtname, *Sitenames[i]) == SAME) {
  736.                 goto scanNext;
  737.             }
  738.         }
  739.         Sitenames[siteCount] = NewHandle(strlen(rmtname) + 1);
  740.         MoveHHi(Sitenames[siteCount]);
  741.         HLock(Sitenames[siteCount]);
  742.         strcpy(*Sitenames[siteCount], rmtname);
  743.         siteCount++;
  744. scanNext: ;
  745.     }
  746.     fclose( fsys );
  747.     fsys = (FILE *)NULL;
  748.     for (i = 0; i < siteCount; i++) {
  749.         for (j = i+1; j < siteCount; j++) {
  750.             if (strcmp(*Sitenames[i], *Sitenames[j]) > 0) {
  751.                 t = Sitenames[i];
  752.                 Sitenames[i] = Sitenames[j];
  753.                 Sitenames[j] = t;
  754.             }
  755.         }
  756.         strcpy(rmtname, *Sitenames[i]);
  757.         HUnlock(Sitenames[i]);
  758.         CtoPstr(rmtname);
  759.         AppendMenu(My_Menus[Call_Menu_Index], rmtname);
  760.     }
  761. }
  762.         
  763.  
  764.  
  765.  
  766. main(argc, argv)
  767.     int    argc;
  768.     char **argv;
  769. {
  770.     int Status;
  771.     int i;
  772.     int appFiles, appFileNo;
  773.     AppFile appFile;
  774.     
  775.     console_options.title = "\pUUPC";
  776.     console_options.nrows = 24;        /* don't need that huge window, */
  777.     console_options.ncols = 64;        /* especially when it's running in background */
  778.     macinit();
  779.  
  780.     /***** setup menu bar *****/
  781.     /* get handles to menu resources */
  782.     My_Menus[Apple_Menu_Index]   = NewMenu(Apple_Menu_Id, "\p\024" );
  783.     My_Menus[File_Menu_Index]    = GetMenu(File_Menu_Id);
  784.     My_Menus[Edit_Menu_Index]    = GetMenu(Edit_Menu_Id);
  785.     My_Menus[Call_Menu_Index]    = GetMenu(Call_Menu_Id);
  786.     
  787.     AppendMenu(My_Menus[Apple_Menu_Index],"\pAbout UUPC...");
  788.     AppendMenu(My_Menus[Apple_Menu_Index],"\p(-");
  789.     AddResMenu(My_Menus[Apple_Menu_Index],'DRVR');    /* get DA names */
  790.     
  791.     for (i=0; i<N_Menus; i++) {
  792.         InsertMenu(My_Menus[i],0);        /* Add menu to menu bar */
  793.     }
  794.  
  795.     DrawMenuBar();
  796.     Set_Main_State(Idle_System);
  797.     
  798.     /* mac specific prolog */
  799.     loadenv();
  800.     
  801.     AppendToCallMenu();
  802.  
  803.     appFiles = Count_Appl_Files();
  804.     appFileNo = 1;
  805.     
  806.     curdir = getcwd( NULL, 0 );
  807. #ifdef CWDSPOOL
  808.     CHDIR( spooldir );
  809. #endif
  810.  
  811.     while (Main_State != Quit_Program && Main_State != Abort_Program && 
  812.            Main_State != Shutdown_Program) {
  813.         
  814.         switch (Main_State) {
  815.             case Idle_System:
  816.                 Check_Events(50);
  817.                 if (appFileNo <= appFiles) {
  818.                     GetAppFiles(appFileNo, &appFile);
  819.                     appFileNo++;
  820.                     PtoCstr((char *) appFile.fName);
  821.                     if (strcmp((char *) appFile.fName, "slave") == 0) {
  822.                         printmsg(0, "Launch request: enter slave mode");
  823.                         strcpy(line, "-r0 -x0 -sslave");
  824.                     } else {
  825.                         sprintf(line, "-r1 -x0 -s%s", appFile.fName);
  826.                         printmsg(0, "Launch request: call %s", appFile.fName);
  827.                     }
  828.                     Set_Main_State(Call_Systems);
  829.                 }
  830.                 break;
  831.                 
  832.             case Call_Systems:
  833.                 Check_Events(MF_DELAY);
  834.                 argc = getargs(line, n_argv);
  835.                 argv = n_argv;
  836. #ifdef BOGUS
  837.                 argc = 3;        /* we always set 3 args now */
  838. #endif
  839.                 
  840.                 MAIN( argc, argv );
  841.                 
  842.                 if (Main_State == Call_Systems) Set_Main_State(Idle_System);
  843.                 break;
  844.             
  845.             case Cancel_Call:
  846.                 Check_Events(MF_DELAY);
  847.                 Set_Main_State(Idle_System);
  848.                 appFiles = 0;
  849.                 break;
  850.                 
  851.             default:
  852.                 Check_Events(MF_DELAY);
  853.                 break;
  854.         }
  855.     }
  856.     
  857.     /* mac specific epilog */
  858.     if (Main_State == Shutdown_Program) {
  859.         ShutDwnPower();
  860.     }
  861.     chdir( curdir );
  862.     exit(0);
  863. }
  864.  
  865. void PlayNamed(char *theName)
  866. {
  867.     Handle h;
  868.     long int flags;
  869.     OSErr osErr;
  870.     /*** this is the WRONG TEST but I can't figure out how to tell whether
  871.          SndPlay is present except by checking for the Apple Sound Chip!
  872.     ***/
  873.     osErr = Gestalt('hdwr', &flags);
  874.     if (osErr == noErr &&
  875.         (flags & 0x8) != 0 &&
  876.         (h = GetNamedResource('snd ', theName)) != NULL) {
  877.         SndPlay(NULL, h, FALSE);
  878.     }
  879. }
  880.  
  881.